package com.example.xgakj.newterminal.ui.dialogs;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.example.xgakj.mylibrary.mvp.utils.CommonUtil;
import com.example.xgakj.newterminal.R;
import com.example.xgakj.newterminal.base.BaseApplication;
import com.example.xgakj.newterminal.base.Parameters;
import com.example.xgakj.newterminal.models.QueryModel;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2017-05-18.
 */

public class UpdateDialog extends DialogFragment {

    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.et_repeat)
    EditText etRepeat;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_commit)
    TextView tvCommit;
    Unbinder unbinder;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_MinWidth);
        setStyle(DialogFragment.STYLE_NO_FRAME, 0);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
            savedInstanceState) {

        View view = inflater.inflate(R.layout.dialog_update, null);

        unbinder = ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.tv_cancel, R.id.tv_commit})
    public void onViewClicked(View view) {
        String password=etPassword.getText().toString().trim();
        String repeat=etRepeat.getText().toString().trim();
        switch (view.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_commit:
                if (!CommonUtil.isNull(password)||password.equals(repeat)){
                    String word= CommonUtil.getMd5(password);
                    String fname = "CUPassWords";
                    String fvalue ="'"+word+"'";
                    String cuid = BaseApplication.usrID;
                    QueryModel.getInstance().updateInfo(Parameters.CUSTOMER, "cuid", cuid, fname, fvalue, new QueryModel.NetCallBack() {
                        @Override
                        public void onSuccess() {
                            dismiss();
                        }

                        @Override
                        public void onFailure() {

                        }
                    });
                    dismiss();
                }
                break;
            default:
        }
    }
}

